package com.twu.biblioteca;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * User: abishek1
 * Date: 8/8/13
 * Time: 6:57 PM
 * To change this template use File | Settings | File Templates.
 */
public class Book implements ReserveableItem{
    int id;
    String name;
    boolean available;
    String reservedBy;
    Book(int id, String name){
        this.id = id;
        this.name = new String(name);
        available = true;
    }
    void displayBook(){
        System.out.print(Integer.toString(id) + "\t\t" + name + "\t\t");
        if(available)
            System.out.println("available");
        else
            System.out.println("reserved");
    }

    void writeBookToFile(BufferedWriter bw){
        try {
            bw.write(Integer.toString(id) + "~" + name + "~");

            if(available)
                bw.write("available\n");
            else
                bw.write("reserved\n");

        }
        catch (IOException e) {
            e.printStackTrace();
        }

    }

    boolean isAvailable(){
        return available;
    }

    int getId(){
        return id;
    }

    public void reserve(String userID){
        reservedBy = new String(userID);
        available = true;
    }

    void unreserve(){
        available = false;
    }
}

